﻿<%@ page language="java" import="java.sql.*,java.util.Date,java.text.SimpleDateFormat" pageEncoding="UTF-8" errorPage="errorpage.jsp"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>更新车票</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->

	<% 
		Date today=new Date();
		SimpleDateFormat f=new SimpleDateFormat("yyyy-MM-dd");
		String dateStr=f.format(today);
		request.setAttribute("ff",dateStr); 
		System.out.println(dateStr);
	%>
	
<link rel="stylesheet" href="image/CSS.CSS" type="text/css">
	<script language="javascript" type="text/javascript" src="My97DatePicker/WdatePicker.js"></script>
<script language=javascript>
//保证时间3天之内
 function strDateTime(str) {
            var r = str.match(/^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2})$/);
            if (r == null) return false;
            var d = new Date(r[1], r[3] - 1, r[4]);
            return (d.getFullYear() == r[1] && (d.getMonth() + 1) == r[3] && d.getDate() == r[4]);
        }

        function btnValidate() {
            var strfrom = document.getElementById("startdate").value;
            var strto = document.getElementById("startdate_hide").value;
            if (!strDateTime(strfrom) && strDateTime(strto)) {
                alert("the date format is not valid");
            }
            else {
                if (DateDiff(strto, strfrom) > 11) {//180 days
                    alert("只能订购10天之内的票:" + DateDiff(strto, strfrom));
                    return false;
                }
                else {
                	
                    return true;
                }
            }
        }

        function DateDiff(sDate1, sDate2) {  
            var aDate, oDate1, oDate2, iDays;
            aDate = sDate1.split("-");
            oDate1 = new Date(aDate[1] + '-' + aDate[2] + '-' + aDate[0]) ;
            aDate = sDate2.split("-");
            oDate2 = new Date(aDate[1] + '-' + aDate[2] + '-' + aDate[0]);
            iDays = parseInt(Math.abs(oDate1 - oDate2) / 1000 / 60 / 60 / 24) ; 
            return iDays;
        } 


function check()
{
	  
  if((document.test.countnumber.value==null)||(document.test.countnumber.value.length==0))
  {   
    alert("订票数为空，请重新输入");
    document.test.countnumber.focus();
    return false;
  } 
	if((document.test.startdate.value==null)||(document.test.startdate.value.length==0))
  {   
    alert("车票日期为空，请重新输入");
    document.test.startdate.focus();
    return false;
  }
 	var b=btnValidate();
	if(b==false){
	return false;
	}
  if((document.test.dingjin.value==null)||(document.test.dingjin.value.length==0))
  {   
    alert("订金为空，请重新输入");
    document.test.dingjin.focus();
    return false;
  }            
  var txt = test.countnumber.value;
  var txt1=test.dingjin.value; 
  if(checknumber(txt1)) 
    { 
        alert("订金只允许输入数字！"); 
        return false; 
    } 
    if(checknumber(txt)) 
    { 
        alert("订票数只允许输入数字！"); 
        return false; 
    } 
  function checknumber(String) 
    { 
        var Letters = "1234567890"; 
        var i; 
        var c; 
        for( i = 0; i < String.length; i ++ ) 
        { 
			c = String.charAt( i ); 
			if (Letters.indexOf( c ) ==-1) 
			{ 
				return true; 
			} 
		} 
		return false; 
	} 
  return true;
}

</script>
  </head>
 <jsp:useBean id="ticket" scope="request" class="com.swjd.bean.ticket"/>
  <BODY BGCOLOR=#ffccCC leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<!--Logo|--开始-->
<table width="778" border="0" cellspacing="0" cellpadding="0" align="center" height="330">
  <tr> 
    <td colspan="3" height="90"><img src="image/index_top1.gif" width="778" height="90"></td>
  </tr>
  <tr> 
    <td height="160" width="518" background="image/index_top2.gif">
      <table border="0" cellspacing="0" cellpadding="0" align="center">
        <tr> 
          <td> 
            <div align="center"><font color="#000000"> <b><font size="7"><font color="#000000">火车订票系统</font>

 
              </font></b></font></div>
          </td>
        </tr>
        
      </table>
    </td>
    <td height="160" width="210" background="image/01.gif"><img src="image/index_pic.gif" width="220" height="160"></td>
    <td height="160" width="40"><img src="image/index_top3.gif" width="40" height="160"></td>
  </tr>
  <tr> 
    <td colspan="3" height="80"><img src="image/index_top4.gif" width="778" height="80"></td>
  </tr>
</table>
<table width="778" border="0" cellspacing="0" cellpadding="0" align="center" bgcolor="#FFFFFF">
  <tr> 
    <td valign="top"> 
      <table width="280" border="0" cellspacing="0" cellpadding="0" background="image/index_lmbg.gif">
        <tr>
		<td align="center">
		</td>
		</tr>
		<tr>
		<td>
	<table width="250" border="0" cellspacing="0" cellpadding="0" height="40" background="image/index_lm.gif">
              <tr> 
                <td> 
                  <div align="center"><b><a href="changepass.jsp">修改密码</a></b></div>
                </td>
              </tr>
            </table>
		</td>
		</tr>

		<tr> 
          <td height="30">
            <table width="250" border="0" cellspacing="0" cellpadding="0" height="40" background="image/index_lm.gif">
              <tr> 
                <td> 
                  <div align="center"><b>
<a href="trainquery1.jsp">
按车次查询</a></b></div>
                </td>
              </tr>
            </table>
            <table width="250" border="0" cellspacing="0" cellpadding="0" height="40" background="image/index_lm.gif">
              <tr> 
                <td> 
                  <div align="center"><b>
<a href="addressquery1.jsp">
按地点查询</a></b></div>
                </td>
              </tr>
            </table>
            <table width="250" border="0" cellspacing="0" cellpadding="0" height="40" background="image/index_lm.gif">
              <tr> 
                <td> 
                  <div align="center"><b>

<a href="stationquery1.jsp">
按站点查询</a></b></div>
                </td>
              </tr>
            </table>
			
            <table width="250" border="0" cellspacing="0" cellpadding="0" height="40" background="image/index_lm.gif">
              <tr> 
                <td> 
                  <div align="center"><b> 
 
<a href="orderstatus.jsp"> 
<!--Button6-->订票情况</a> </b></div>
                </td>
              </tr>
            </table>   
            <table width="250" border="0" cellspacing="0" cellpadding="0" height="40" background="image/index_lm.gif">
            </table>
            <table width="250" border="0" cellspacing="0" cellpadding="0" height="40" background="image/index_lm.gif">
              <tr> 
                <td> <div align="center"><b> 
<a href="logincheck?action=logout"> 
退出登录</a> </b></div></td>
              </tr>
            </table>
            <table width="250" border="0" cellspacing="0" cellpadding="0" height="40" background="image/index_lm.gif">
              
            </table>
			</td>
          <td width="30" height="30">&nbsp;</td>
        </tr>
        <tr> 
          <td colspan="2"> <img src="image/index_bottom.gif" width="280" height="100"></td>
        </tr>
      </table>
      <p>&nbsp;</p>
    </td>
    <td width="468" valign="top"> 
      <table width="458" border="0" cellspacing="0" cellpadding="0" style="width: 458px; height: 340px;" height="340">
        <tr> 
          <td>&nbsp;</td>
        </tr>
        <tr> 
          <td>
            <table width="90%" border="0" cellspacing="0" cellpadding="0" align="center">
         
                
              <tr> 
                <td bgcolor="#000000"><img src="images/Spacer.gif" width="1" height="1"></td>
              </tr>
              <tr> 
                <td> 
                  <div align="right">

				  </div>
                </td>
              </tr>
              

  <%
  String user_id = (String)session.getAttribute("name1");
if(user_id==null){response.sendRedirect("hello.jsp");}
String t_id=request.getParameter("trainid");
String s_id=new String(request.getParameter("start").getBytes("ISO-8859-1"),"UTF-8");
String s_id1=new String(request.getParameter("dest").getBytes("ISO-8859-1"),"UTF-8");
%>

<p align="center"><font color="#000000" size="+1" face="方正舒体">订票</font></p>
<form  method="post" action="ticketsvlt" onsubmit="return check()" name=test>
  <input type="hidden" name="action" value="order">
  <input type="hidden" name="userid" value="<%=user_id %>">
  <table width="49%" height="50"  border="1" align="center" cellpadding="0" cellspacing="0">
    <tr> 
      <td width="48%">车次</td>
      <td width="52%"><input name="trainid" type="text"  id="trainid" value="<%=t_id%>"></td>
    </tr>
    <tr> 
      <td width="48%">起始站</td>
      <td width="52%"><input name="startplace" type="text"  id="startplace" value="<%=s_id%>"></td>
    </tr>
	<tr> 
      <td width="48%">终点站</td>
      <td width="52%"><input name="destination" type="text"  id="destination" value="<%=s_id1%>"></td>
    </tr>
    <tr> 
      <td width="48%">订票数目</td>
      <td width="52%"><input name="countnumber" type="text"  id="countnumber" ></td>
    </tr>
    <tr> 
      <td width="48%">车票日期</td>
      <td width="52%"><input name="startdate" type="text"  id="startdate" onClick="WdatePicker()"></td>
      <td><input name="startdate_hide" type="hidden" value="<%=request.getAttribute("ff")%>" /></td>
    </tr>
    <tr> 
      <td width="48%">订金</td>
      <td width="52%"><input name="dingjin" type="text"  id="dingjin" ></td>
    </tr>
    <tr> 
      <td width="48%">火车类型</td>
      <td><select name="typeid" size="1" id="typeid">
          <option value=1>普快</option>
          <option value=2>特快</option>
          <option value=3>动车</option>
        </select></td>
    </tr>
  </table>
  <p align="center"> 
    <input type="submit" name="Submit" value="提交">
  </p>
</form>
<p>&nbsp;</p>
            </table> 
            <table width="90%" border="0" cellspacing="0" cellpadding="0" align="center" class="englishfont" height="1">
              <tr> 
                <td bgcolor="#000000"> </td>
              </tr>
            </table>
            <table width="96%" border="0" cellspacing="0" cellpadding="4" align="bottom">
              <tr> 
                <td> 
                  <div align="center"> 
火车在线订票
 ！
@2020<br>
                      车站地址:湖南省长沙市芙蓉区科教路<br>
                      电话:0731-8888888<br>
                      电子邮件:train@gmail.com
                </td>
              </tr>
            </table>      
		  </td>
        </tr>
      </table>

    </td>
    <td width="30">&nbsp;</td>
  </tr>
</table>
</BODY>
</html>
